/**
 * 
 */
package dms.dto;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

/**
 * @author 李健
 *
 */
public class LowElectricityDTO extends ActionForm {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Long id;
	private String dormitory;
	private String building;
	private String date;
	private String degree;
	private String fromDate;
	private String toDate;
	//LowElectricity列表时用到的按某种方式查询,取值为dormitory,building
	private String type;
	
	public String getFromDate() {
		return fromDate;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public void setFromDate(String fromDate) {
		this.fromDate = fromDate;
	}
	public String getToDate() {
		return toDate;
	}
	public void setToDate(String toDate) {
		this.toDate = toDate;
	}
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public String getDormitory() {
		return dormitory;
	}
	public void setDormitory(String dormitory) {
		this.dormitory = dormitory;
	}
	public String getDate() {
		return date;
	}
	public void setDate(String date) {
		this.date = date;
	}

	public String getDegree() {
		return degree;
	}
	public void setDegree(String degree) {
		this.degree = degree;
	}
	public String getBuilding() {
		return building;
	}
	public void setBuilding(String building) {
		this.building = building;
	}
	
	@Override
	public void reset(ActionMapping mapping, HttpServletRequest request) {
		this.id = null;
		this.date = null;
		this.degree = null;
		this.dormitory = null;
		this.building = null;
		this.type = null;
	}
	
	@Override
	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {
		ActionErrors errors = new ActionErrors();
		
		if (this.dormitory == null || this.dormitory.length() == 0) {
			errors.add("dormitory", new ActionMessage("寝室为空", false));
		}
		if (this.degree == null || this.degree.length() == 0) {
			errors.add("degree", new ActionMessage("剩余度数为空", false));
		}
		if (this.date == null || this.date.length() == 0) {
			errors.add("date", new ActionMessage("发布日期为空", false));
		}
		if (!errors.isEmpty()) {
			request.setAttribute("status", false);
			request.setAttribute("message", "缺少信息");
		}
		return errors;
	}
}
